﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Wormhole.Engine.Communication
{
	#region Delegates
	/// <summary>
	/// The random seed received delegate.
	/// </summary>
	/// <param name="seed">The random seed received from the other player.</param>
	public delegate void RandomSeedReceivedDelegate(int seed);

	/// <summary>
	/// The delegate for the event that is raised when an open game is received.
	/// </summary>
	/// <param name="game">The open game that was received.</param>
	public delegate void OpenGameReceivedDelegate(Game game);

	/// <summary>
	/// The delegate for the event that is raised when a deck is received.
	/// </summary>
	/// <param name="deck">The deck of cards that was received.</param>
	public delegate void DeckReceivedDelegate(Deck deck);

	/// <summary>
	/// The delegate for the event which is raised when a player requests to join a game.
	/// </summary>
	/// <param name="game">The game the request is for.</param>
	/// <param name="playerName">The name of the player making the request.</param>
	public delegate void JoinRequestDelegate(Game game, string playerName);

	/// <summary>
	/// Handle the event that is raised when a response is received for a game join request.
	/// </summary>
	/// <param name="game">The game the message is for.</param>
	/// <param name="accepted">True when the request is accepted.</param>
	/// <param name="message">The response message.</param>
	public delegate void JoinResponseDelegate(Game game, bool accepted, string message);

	/// <summary>
	/// The delegate for the event that is raised when a game is closed..
	/// </summary>
	/// <param name="game">The game that was closed.</param>
	public delegate void GameClosedDelegate(Game game);

	/// <summary>
	/// The delegate for the keep hand event.
	/// </summary>
	public delegate void KeptHandDelegate();

	/// <summary>
	/// The take mullilgan delegate.
	/// </summary>
	public delegate void TookMulliganDelegate();
	
	/// <summary>
	/// The delegate for the event that is raised when a card action is performed.
	/// </summary>
	/// <param name="action">The card action.</param>
	public delegate void CardActionDelegate(Action.CardAction action);

	/// <summary>
	/// The delegate for the event that is raised when a game action is performed.
	/// </summary>
	/// <param name="action">The game action.</param>
	public delegate void GameActionDelegate(Action.GameAction action);
	#endregion

	#region IClient
	/// <author>Hannes Foulds</author>
	/// <date>01 September 2008</date>
	/// <summary>
	/// The interface for the communications client.
	/// The IRC implementation should inherit from this interface.
	/// </summary>
	public interface IClient
	{
		void Disconnect();

		/// <summary>
		/// Create a new game.
		/// </summary>
		/// <param name="description">The game description.</param>
		void CreateGame(string description);

		/// <summary>
		/// Request a list of games available for joining.
		/// </summary>
		void RequestOpenGameList();

		/// <summary>
		/// Attempt to join a game.
		/// </summary>
		/// <param name="id">The ID of the game to join.</param>
		void JoinGame(Guid id);

		/// <summary>
		/// This event is raised when and open game is received.
		/// </summary>
		event OpenGameReceivedDelegate OpenGameReceived;

		/// <summary>
		/// Send the random seed to the other player.
		/// </summary>
		/// <param name="seed">The random seed.</param>
		void SendRandomSeed(int seed);

		/// <summary>
		/// This event is raised when a the random seed of the other player is received.
		/// </summary>
		event RandomSeedReceivedDelegate RandomSeedReceived;

		/// <summary>
		/// Send a deck to the other player.
		/// </summary>
		/// <param name="deck">The deck of cards to send.</param>
		void SendDeck(Deck deck);

		/// <summary>
		/// The deck received event.
		/// </summary>
		event DeckReceivedDelegate DeckReceived;

		/// <summary>
		/// This event is raised when a response to a game join request is received.
		/// </summary>
		event JoinResponseDelegate JoinResponse;

		/// <summary>
		/// This event is raised when another player requests a game join.
		/// </summary>
		event JoinRequestDelegate JoinRequest;

		/// <summary>
		/// Accept a join request.
		/// </summary>
		/// <param name="id">The ID of the game.</param>
		/// <param name="playerName">The name of the player requesting the join.</param>
		/// <param name="response">The message</param>
		void AcceptJoin(Guid id, string playerName, string message);

		/// <summary>
		/// Reject a join request.
		/// </summary>
		/// <param name="id">The ID of the game.</param>
		/// <param name="playerName">The name of the player requesting the join.</param>
		/// <param name="response">The message</param>
		void RejectJoin(Guid id, string playerName, string message);

		/// <summary>
		/// This event is raised when a game is closed.
		/// </summary>
		event GameClosedDelegate GameClosed;

		/// <summary>
		/// Close the game.
		/// </summary>
		/// <param name="remove">Should the game also be removed.</param>
		void CloseGame(bool remove);

		/// <summary>
		/// Keep the hand that was dealt.
		/// </summary>
		void KeepHand();

		/// <summary>
		/// This event is taised when the kept hand message is received.
		/// </summary>
		event KeptHandDelegate KeptHand;

		/// <summary>
		/// Take a mullican.
		/// </summary>
		void TakeMulligan();

		/// <summary>
		/// This event is raised when the opponent took a mulligan.
		/// </summary>
		event TookMulliganDelegate TookMulligan;

		void PerformCardAction(Action.CardAction action);

		/// <summary>
		/// This event is raised when a card action is performed.
		/// </summary>
		event CardActionDelegate CardAction;

		/// <summary>
		/// Send a game action message.
		/// </summary>
		/// <param name="action">The game action to send.</param>
		void PerformGameAction(Action.GameAction action);

		/// <summary>
		/// This event is raised when a game action is performed.
		/// </summary>
		event GameActionDelegate GameAction;
	}
	#endregion
}
